import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/ManagerView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'manager',
    redirect:'/home',
    component: HomeView,
    children:[{
      path:'home',
      name:'home',
      meta:{
        name:'首页',
      },
      component:()=>import('../views/manager/HomeView.vue')
    },{
      path:'index',
      name:'index',
      meta:{
        name:'index类型'
      },
      component:()=>import('../views/manager/IndexView.vue')
    },{
      path:'metric',
      name:'metric',
      meta:{
        name:'metric类型'
      },
      component:()=>import('../views/manager/MetricView.vue')
    },{
      path:'network',
      name:'network',
      meta:{
        name:'network类型'
      },
      component:()=>import('../views/manager/NetworkView.vue')
    }
  ]
  },{
    path:'/login',
    name:'login',
    meta:{
      name:'登录页面'
    },
    component:()=>import('../views/Login.vue')
  },{
    path:'/register',
    name:'register',
    meta:{
      name:'登录页面'
    },
    component:()=>import('../views/Register.vue')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 重复点击当前的路由的时候会报错，这里来处理一下
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(error=>error)
}

export default router
